<?php
if (!current_user_can('manage_options'))
		{
			wp_die('You do not have sufficient permissions to access this page.');
		}
        $store_prefix = get_option('cpx_store_prefix');
        $aff_out_link_old = get_option('aff_out_link_prefix');
        $aff_out_link_prefix_cp = get_option('aff_out_link_prefix_cp'); 
        $test_in_localhost = get_option('test_in_localhost');
?>
        <div class="wrap">  
        <?php screen_icon('themes'); ?><h2>General</h2>
        <form method="POST" action="">  
            <table class="form-table">  
                <tr valign="top">  
                    <th scope="row">  
                        <label for="store_prefix">Default additional store name prefix</label>   
                    </th>  
                    <td>  
                        <input value="<?php echo ($_POST['store_prefix']?$_POST['store_prefix']:$store_prefix); ?>" name="store_prefix" type="text" placeholder="ex: coupon, voucher, promotion code, etc. " style="width: 250px;"/>  
                    </td>  
                </tr>
                <tr>
                    <th>
                        <label>Default prefix out affiliate link store</label>
                    </th>
                    <td>
                        <input value="<?php echo ($_POST['aff_out_link_prefix']?$_POST['aff_out_link_prefix']:$aff_out_link_old); ?>" name="aff_out_link_prefix" type="text" placeholder="ex: go, out, etc. " style="width: 250px;"/>
                    </td>
                </tr>
                <tr>
                    <th>
                        <label>Default prefix out affiliate link coupon</label>
                    </th>
                    <td>
                        <input value="<?php echo ($_POST['aff_out_link_prefix_cp']?$_POST['aff_out_link_prefix_cp']:$aff_out_link_prefix_cp); ?>" name="aff_out_link_prefix_cp" type="text" placeholder="ex: go, out, etc. " style="width: 250px;"/>
                    </td>
                </tr>
                <tr>
                    <th>
                        <label>Run CouponX in localhost ?</label>
                    </th>
                    <td>
                        <input value="<?php echo ($_POST['test_in_localhost']?$_POST['test_in_localhost']:$test_in_localhost); ?>" name="test_in_localhost" type="text" placeholder="0 = No, 1 = Yes" style="width: 150px;"/>
                    </td>
                </tr>
            </table>
            <p>  
                <input type="submit" value="Save settings" class="button-primary"/>
            </p>   
        </form>  
        </div> 
        
<?php
        if(isset($_POST["store_prefix"]) || isset($_POST['aff_out_link_prefix']) || isset($_POST['test_in_localhost']) || isset($_POST['aff_out_link_prefix_cp']))
        {
            // update store prefix
            $new_prefix = esc_attr($_POST["store_prefix"]);  
            update_option('cpx_store_prefix', $new_prefix);
            // update affiliate out link store
            $new_outlink_st = esc_attr($_POST["aff_out_link_prefix"]);
            update_option('aff_out_link_prefix', $new_outlink_st);
            // update aff_out_link_prefix_cp
            $new_outlink_cp = esc_attr($_POST["aff_out_link_prefix_cp"]);
            update_option('aff_out_link_prefix_cp', $new_outlink_cp);
            // update test in localhost or not
            $test_lc = esc_attr($_POST["test_in_localhost"]);
            update_option('test_in_localhost', $test_lc);
            // print success message
            echo '<div id="message" class="updated">Settings saved</div>';
        }